import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects

Window  {
    id: window
    width: 800
    height: 800
    visible: true
    flags: Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint|Qt.Window
    property int barHeight: 35
    property int iconSize: 15

    Item {
        z : -1
        anchors.fill: parent

        // 左侧边缘
        MouseArea {
            width: 5
            anchors {
                left: parent.left
                top: parent.top
                bottom: parent.bottom
            }
            cursorShape: Qt.SizeHorCursor
            onPressed: window.startSystemResize(Qt.LeftEdge)
        }

        //右侧边缘
        MouseArea {
            width: 5
            anchors {
                right: parent.right
                top: parent.top
                bottom: parent.bottom
            }
            cursorShape: Qt.SizeHorCursor
            onPressed: window.startSystemResize(Qt.RightEdge)
        }

        //下侧边缘
        MouseArea {
            height: 5
            anchors {
                right: parent.right
                left:parent.left
                bottom: parent.bottom
            }
            cursorShape: Qt.SizeVerCursor
            onPressed: window.startSystemResize(Qt.BottomEdge)
        }

        //上侧边缘
        MouseArea {
            hoverEnabled: true  // 核心修复项
            height: 5
            anchors {
                right: parent.right
                left:parent.left
                top: parent.top
            }
            cursorShape: Qt.SizeVerCursor
            onPressed: {
                window.startSystemResize(Qt.TopEdge)}
        }

        // 示例：右下角
        MouseArea {
            width: 10
            height: 10
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            cursorShape: Qt.SizeFDiagCursor
            onPressed: window.startSystemResize(Qt.RightEdge | Qt.BottomEdge)
        }

        //右上角
        MouseArea {
            width: 10
            height: 10
            anchors.right: parent.right
            anchors.top: parent.top
            cursorShape: Qt.SizeFDiagCursor
            onPressed: window.startSystemResize(Qt.RightEdge | Qt.TopEdge)
        }

        //左上角
        MouseArea {
            width: 10
            height: 10
            anchors.left: parent.left
            anchors.top: parent.top
            cursorShape: Qt.SizeFDiagCursor
            onPressed: window.startSystemResize(Qt.LeftEdge | Qt.TopEdge)
        }

        //左下角
        MouseArea {
            width: 10
            height: 10
            anchors.left: parent.left
            anchors.bottom: parent.bottom
            cursorShape: Qt.SizeFDiagCursor
            onPressed: window.startSystemResize(Qt.LeftEdge | Qt.BottomEdge)
        }
    }

    Rectangle {
        id: titleBar
        height: barHeight
        width: window.width
        color: '#ededed'
        Row {
            anchors.fill: parent
            spacing: 0

            HTitleBar{
                width: window.width
                height: barHeight
                onWPositionChanged: (x,y)=>{
                    window.setX(window.x + x)
                    window.setY(window.y + y)
                }

                onWWindowsMinimizedCmd: {
                    window.showMinimized()
                }

                onWWindowsMaximizedCmd: {
                    if (window.visibility === Window.Maximized) {
                               window.showNormal();
                           } else {
                               window.showMaximized();
                        }
                }

                onWWindowsCloseedCmd: {
                    window.close()
                }
            }
        }
    }
}
